import CONSTANT from '../../constant';
import cookies from '../../helpers/cookies';

export default function (poster) {
    const CLIENT_INFO_POST = cookies.read('CLIENT_INFO_POST');
    if (CLIENT_INFO_POST) {
        return;
    }

    const nav = navigator;
    const clieninfo = {
        appCodeName: encodeURIComponent(nav.appCodeName),
        appName: encodeURIComponent(nav.appName),
        platform: encodeURIComponent(nav.platform),
        product: encodeURIComponent(nav.product),
        userAgent: encodeURIComponent(nav.userAgent),
        // 屏幕分辨率
        wh: window.screen.height,
        ww: window.screen.width,
        // 屏幕宽高
        dw: document.body? document.body.clientWidth:0,
        dh: document.body? document.body.clientHeight:0,
        // 屏幕可用工作区宽高
        ah: window.screen.availHeight,
        aw: window.screen.availWidth,
        // 调色板的比特深度
        cd: window.screen.colorDepth,
        dXDPI: window.screen.deviceXDPI || ''
    };

    clieninfo.uuid = CONSTANT.uuid;
    clieninfo.type = 'client';

    // 记录代码异常
    poster.sendDataByImg(clieninfo);

    const y = new Date().getFullYear() + 50; // 年份加50
    let expires = y + '/12/30';
    expires = new Date(expires).getTime();
    cookies.write('CLIENT_INFO_POST', 1, expires);

}